package com.hksj.cbm.controller;

import com.hksj.cbm.dto.DeviceCategoryDTO;
import com.hksj.cbm.entity.DeviceCategory;
import com.hksj.cbm.service.DeviceCategoryService;
import com.hksj.common.core.model.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zengke
 * @version 1.0
 * @see DeviceCategoryController
 * @since 2024/08/28 14:40
 */

@Api(tags = "基础模块-设备分类管理")
@RestController
@RequestMapping("/api/deviceCategory")
public class DeviceCategoryController {

    @Autowired
    private DeviceCategoryService deviceCategoryService;

    @ApiOperation(value = "新增设备分类")
    @PostMapping("/createDeviceCategory")
    public Rest<String> createDeviceCategory(@RequestBody @Validated DeviceCategoryDTO deviceCategoryDTO){
        String result = deviceCategoryService.createDeviceCategory(deviceCategoryDTO);
        return Rest.ok(result);
    }

    @ApiOperation(value = "更新设备分类")
    @PutMapping("/updateDeviceCategory")
    public Rest<String> updateDeviceCategory(@RequestBody @Validated DeviceCategoryDTO deviceCategoryDTO){
        String result = deviceCategoryService.updateDeviceCategory(deviceCategoryDTO);
        return Rest.ok(result);
    }

    @ApiOperation(value = "删除设备分类")
    @DeleteMapping("/deleteDeviceCategory")
    public Rest<String> deleteDeviceCategory(String code){
        String result = deviceCategoryService.deleteDeviceCategory(code);
        return Rest.ok(result);
    }

    @ApiOperation(value = "查询设备分类列表")
    @PostMapping("/queryDeviceCategoryList")
    public Rest<List<DeviceCategory>> queryDeviceCategoryList(){
        List<DeviceCategory> deviceCategoryList = deviceCategoryService.queryDeviceCategoryList();
        return Rest.ok(deviceCategoryList);
    }

    @ApiOperation(value = "查询设备分类树")
    @PostMapping(value = "/queryDeviceCategoryTree")
    public Rest<List<DeviceCategory>> queryDeviceCategoryTree(){
        List<DeviceCategory> deviceCategoryTree = deviceCategoryService.queryDeviceCategoryTree();
        return Rest.ok(deviceCategoryTree);
    }
}
